package org.cytoscape.myapp.cytoscape_app_v1.internal;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;

import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.group.CyGroup;
import org.cytoscape.group.CyGroupFactory;
import org.cytoscape.group.CyGroupManager;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.Clasificador;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.ClasificadorOr;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.ClasificadorXor;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.ClasificadorXorBest;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.Comparador;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.ComparadorContenido;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.ComparadorIgual;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.ComparadorOr;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.Conjunto;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.Criterio;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.CriterioVariable;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.CriterioVerdadero;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.FactoryInterface;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.FactoryNoSensitive;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.FactorySensitive;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.GeneradorGrupos;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.Grupos;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.ModelUtils;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.StringComun;
import org.cytoscape.myapp.cytoscape_app_v1.internal.grupos.StringExtendido;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.CyNetworkViewManager;
import org.cytoscape.work.TaskIterator;
import org.cytoscape.work.TaskManager;

public class CasosTest {
	
	public void init(CyNetwork network, CyGroupManager mnGroup, CyGroupFactory facGroup, 
							CyNetworkViewManager networkViewManager, CyApplicationManager applicationManager,
								TaskManager taskManager ){
		
		
		
		
		
		
		
	//	Comparador compUno = new ComparadorIgual("La Bersuit");
		Comparador acdc = new ComparadorContenido("ac/dc");
		//Comparador compTres = new ComparadorIgual("Avicci");
		Comparador renga = new ComparadorContenido("renga");
		Comparador callejeros = new ComparadorContenido("callejeros");
		
		
		Comparador compCinco = new ComparadorOr(renga,callejeros);
	//	Comparador compSeis = new ComparadorOr(compUno,compTres);	
		
		
		/*Conjunto conjuntoUno = new Conjunto();
		conjuntoUno.annadir(new StringExtendido("bersuit"));
		conjuntoUno.annadir(new StringExtendido("la vela puerca"));
		*/
		FactoryNoSensitive factNoSense = new FactoryNoSensitive(); 
		
		Criterio criterioUno = new CriterioVariable(acdc, "grupo1",factNoSense);
		Criterio criterioDos = new CriterioVariable(compCinco, "grupo2",factNoSense);
		/*
		Conjunto conjuntoDos = new Conjunto();
		conjuntoDos.annadir(new StringExtendido("Metallica"));
		conjuntoDos.annadir(new StringExtendido("Led zeppelin"));*/
		
	//	Criterio criterioDos = new CriterioVariable(conjuntoDos, "GrupoRockPesado");
		
		//Conjunto conjuntoN = new Conjunto();
		
		Criterio criterioN = new CriterioVerdadero(null, "Resto",null);
		
		Vector<String> names = new Vector<String>();
		names.add("grupo1");
		names.add("grupo2");
		names.add("Resto");
	
		//criterios.add(criterioUno);
	//	criterios.add(criterioDos);
	//	criterios.add(criterioN);
		
		
		
		//Grupos grupos = new Grupos(mnGroup, facGroup, names, network,applicationManager);
		
		
		
		String music = " music ";
		
	/*	Set<Object> values = ModelUtils.getValuesCyColumnNetwork(network, music);
		for(Object val:values){
			
			Comparador comparador = new ComparadorIgual(val);
			Criterio criterio = new CriterioVariable(comparador, val.toString(), constructorComp)
			
		}-**/
		
		
		Vector<Criterio> criterios = new Vector<Criterio>();
		FactoryInterface factSense = new FactorySensitive(); 
		String city = " Gender ";
		Set<Object> citys = ModelUtils.getValuesCyColumnNetwork(network, city);
		for(Object cit:citys){
			Comparador or= new ComparadorIgual(cit);
			Criterio crit = new CriterioVariable(or, cit.toString(), factSense);
			criterios.add(crit);
		}
		Clasificador clasificador = new ClasificadorXor(criterios);
		//GeneradorGrupos generador = new GeneradorGrupos(network, clasificador, grupos, ModelUtils.getAllNodesWhitAttributesSimple(network, city));
		//taskManager.execute(new TaskIterator(generador));
		
		
		//generar.Ejecutar(network, clasificador, grupos, ModelUtils.getAllNodesWhitAttributes(network, music));
		
		
		System.out.println("Fin ejecucion");
		
		
	}
	public void RemoveAllGroups(CyNetwork network, CyGroupManager mnGroup,CyNetworkViewManager networkViewManager){

		Set<CyGroup> grupos = mnGroup.getGroupSet(network);
		Vector<CyNode> padres = new Vector<CyNode>();
		for(CyGroup grupo:grupos){
			mnGroup.destroyGroup(grupo);
			padres.add(grupo.getGroupNode());
		}
		network.removeNodes(padres);
		Collection<CyNetworkView> views = networkViewManager.getNetworkViews(network);
		for(CyNetworkView view:views)
			view.updateView();
	}
	
	public void collapased(CyNetwork network, CyGroupManager mnGroup,CyNetworkViewManager networkViewManager){
		
		
		Set<CyGroup> gr = mnGroup.getGroupSet(network);
		for(CyGroup g:gr)
			if (g != null) 
				if(!g.isCollapsed(g.getGroupNetwork()))
					g.collapse(network);
				else
					g.expand(network);
		
		Collection<CyNetworkView> views = networkViewManager.getNetworkViews(network);
		for(CyNetworkView view:views)
			view.updateView();
	}

}
